package app.controller.command
{
	import app.model.global.ApplicationModel;
	import app.service.loader.URLLoaderServiceInterface;
	
	import org.robotlegs.mvcs.Command;
	import app.service.event.SharedObjectServiceEvent;
	import app.service.event.URLLoaderServiceEvent;
	
	public class LoadConfigCommand extends Command
	{
		[Inject]
		public var appModel:ApplicationModel;
		
		[Inject(name="configLoader")]
		public var configLoader:URLLoaderServiceInterface;
		
		[Inject]
		public var event:URLLoaderServiceEvent;

		
		override public function execute():void
		{
			trace('LoadConfigCommand.execute');
			
			switch(event.type)
			{
				case URLLoaderServiceEvent.LOAD_CONFIG:
					appModel.configXML = event.configXML;
					appModel.configENV = event.configENV;
					configLoader.loadURL( appModel.configXML );
					break;
				case URLLoaderServiceEvent.CONFIG_DATA_LOADED:
					
					//when cofig is loaded, we initialize the shared object 
					dispatch( new SharedObjectServiceEvent(SharedObjectServiceEvent.INIT_SHARED_OBJECT) );
					
					break;
			}
			
			
			
			
			
		}
	}
}